﻿var ItemTypeData=[{code:'0',name:'时间型'},{code:'1',name:'用表型'},{code:'2',name:'其他型'}];
//初始化入口
$(function() {
    dlg_statitem_close();
    dlg_serviceitem_close();
    grid_statitem_show();
    grid_serviceitem_show();
    fn_InitCheckBox();
    
    $('#formserviceitemtype').combobox('loadData',ItemTypeData);
});

function grid_statitem_show(){
    $('#statitemGird').datagrid({
        url:'../Controller.aspx?controller=ServiceItemController&method=GetStatItemData',
        onClickRow:function(rowIndex, rowData){
            grid_serviceitem_load(rowData.Code);
        },
        onDblClickRow:function(rowIndex, rowData){alert(rowIndex);}
    });
}
function grid_serviceitem_show(){
    $('#serviceitemGird').datagrid({
        url:'../Controller.aspx?controller=ServiceItemController&method=GetServiceItemData&_statCode=',
        onDblClickRow:function(rowIndex, rowData){alert(rowIndex);}
    });
}

function grid_serviceitem_load(value){
    $('#serviceitemGird').datagrid({url:'../Controller.aspx?controller=ServiceItemController&method=GetServiceItemData&_statCode='+(typeof value=='undefined'?'':value)});
}

function dlg_statitem_close(){
    $('#dlg-statitem').dialog('close');
}

function dlg_statitem_confirm(){
    FormSubmit($('#formstatitem'),'../Controller.aspx?controller=ServiceItemController&method=SaveStatItem',function(){
        dlg_statitem_close();
        $('#statitemGird').datagrid('reload');
    });
}

function dlg_serviceitem_close(){
    $('#dlg-serviceitem').dialog('close');
}

function dlg_serviceitem_confirm(){
    FormSubmit($('#formserviceitem'),'../Controller.aspx?controller=ServiceItemController&method=SaveServiceItem',function(){
        dlg_serviceitem_close();
        $('#serviceitemGird').datagrid('reload');
    });
}

function toolbar_statitem_add(){
    $('#dlg-statitem').dialog({title:'添加统计分类'});
    $('#formstatitem').form('clear');
    $('#formstatitemtype').val('add');
    $('#formstatitemcode').removeAttr('readonly');
}

function toolbar_statitem_alter(){
    var selected=$('#statitemGird').datagrid('getSelected');
    if(selected){
        $('#dlg-statitem').dialog({title:'修改统计分类'});
        $('#formstatitem').form('load',selected);
        $('#formstatitemcode').attr('readonly','readonly');
        $('#formstatitemtype').val('alter');
    }
}

function toolbar_statitem_del(){
    var selected=$('#statitemGird').datagrid('getSelected');
    if(selected){
        $.messager.confirm('询问', '是否要删除此记录？', function(r){
				if (r){
					 requestAjax('../Controller.aspx?controller=ServiceItemController&method=DeleteStatItem', { Code: selected.Code }, function(data) {
                            $('#statitemGird').datagrid('reload');
                        });
				}
			});
    }
}


function toolbar_service_add(){
    $('#dlg-serviceitem').dialog({title:'添加服务项目'});
    $('#formserviceitem').form('clear');
    $('#formservicestat').combobox({url:'../Controller.aspx?controller=ServiceItemController&method=GetStatItemList'});
    var selected=$('#statitemGird').datagrid('getSelected');
    if(selected){
        $('#formservicestat').combobox('setValue',selected.Code);
    }
    $('#DeleteFlag').val(0);
    $('#formservicetype').val('add');//type
    $('#formservicecode').removeAttr('readonly');
}

function toolbar_service_alter(){
    var selected=$('#serviceitemGird').datagrid('getSelected');
    if(selected){
        $('#dlg-serviceitem').dialog({title:'修改服务项目'});
        $('#formserviceitem').form('clear');
        $('#formservicestat').combobox({url:'../Controller.aspx?controller=ServiceItemController&method=GetStatItemList'});
        $('#formserviceitem').form('load',selected);
        $('#formservicecode').attr('readonly','readonly');
        $('#formservicetype').val('alter');//type
        if($('#DeleteFlag').val()=='1'){
            $("#formservicedel").attr("checked","checked");
        }
    }
}

function fn_InitCheckBox() {
    $("#formservicedel").click(function() {
        if ($("#formservicedel").attr("checked")) {
            $("#DeleteFlag").val(1);
        }
        else {
            $("#DeleteFlag").val(0);
        }
    });
    
}


function serviceitemFormatter(value){
    var statdata=$('#statitemGird').datagrid('getData').rows;
	for(var i=0; i<statdata.length; i++){
		if (statdata[i].Code == value) return statdata[i].StatName;
	}
	return value;
}

